# -*- coding: utf-8 -*-

from PySide2.QtCore import Qt

from TESS_PythonAPI.Tessng import TessPlugin, tngIFace
from tess_local_simulator.CustomSimulator import CustomSimulator

from tess_local_simulator.MyNet import MyNet


# 用户插件，继承自TessPlugin
class CustomPlugin(TessPlugin):
    def __init__(self, config_dict: dict):
        super(CustomPlugin, self).__init__()
        self.mNetInf = None
        self.mSimuInf = None
        self.config_dict = config_dict

    def init(self):
        self.mNetInf = MyNet(self.config_dict)
        self.mSimuInf = CustomSimulator(self.config_dict)
        # self.mSimuInf.initVehicle(self)

        iface = tngIFace()
        win = iface.guiInterface().mainWindow()
        # 将信号mSimuInf.forReStopSimu关联到主窗体的槽函数doStopSimu，可以借安全地停止仿真运行
        self.mSimuInf.forStopSimu.connect(win.doStopSimu, Qt.QueuedConnection)
        # 将信号mSimuInf.forReStartSimu关联到主窗体的槽函数doStartSimu，可以借此实现自动重复仿真
        self.mSimuInf.forReStartSimu.connect(win.doStartSimu, Qt.QueuedConnection)

    # 过载父类方法，返回插件路网子接口，此方法由TESS NG调用
    def customerNet(self):
        return self.mNetInf

    # 过载父类方法，返回插件仿真子接口，此方法由TESS NG调用
    def customerSimulator(self):
        return self.mSimuInf
